﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/// <summary>
/// 保存上阵英雄信息
/// </summary>
public class SaveBattleHero
{
    private List<Actors> battleActor = new List<Actors>();
    private string heroId = "";
    private int positionId = -1;
    //private string name = "";
    private static SaveBattleHero instance = new SaveBattleHero();

    public static SaveBattleHero Instance
        {
            get
            {
                return instance;
            }
        }
        private SaveBattleHero() { }


   /// <summary>
   /// 查看上阵英雄信息
   /// </summary>
    public void GetBattleActorInfo() 
    {
       List<int> fpidsList = new List<int>();
        List<string> heroidList = new List<string>();
        if (battleActor.Count != 0)
        {
            foreach (var item in battleActor)
            {
                this.heroId = item.heroid;
                this.positionId = item.formationPositionId;
                //this.name = item.name;
                heroidList.Add(heroId);
                fpidsList.Add(positionId);
                //Debug.Log("heroId = " + this.heroId + ";positionId = " + this.positionId + ";name = "+this.name );
            }
          
            string[] heroIds = heroidList.ToArray();
            int[] fpids = fpidsList.ToArray();

            if( heroIds.Length<=0 || fpids.Length<=0)
            {
                Debug.LogError( "[DEBUG] 没选择人物" );
                return;
            }
            
            Battle.Engine.Test.SetHeroCamp(fpids, heroIds);
           
            
        }
       
    }

    /// <summary>
    /// 添加上阵英雄信息
    /// </summary>
    public void AddHeroForBattle(Actors actor) 
    {
        if (!battleActor.Contains(actor))//如果数据不存在，就添加
        {
            battleActor.Add(actor);
            Debug.Log("添加了一个");
        }

    }
    /// <summary>
    /// 删除上阵英雄信息
    /// </summary>
    public void DeleteHeroForBattle(Actors actor) 
    {
        if (battleActor.Contains(actor))//如果数据存在，删除本条数据
        {
            battleActor.Remove(actor);

            Debug.Log("删除了一个");
        }
    }
    /// <summary>
    /// 清空一下原来的缓存
    /// </summary>
    public void ClearHeroCache() 
    {
        //if (battleActor.Count > 4 )
        //{
            battleActor.Clear();
            
        //}
    }

}

